package helloworld.example.search;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import helloworld.example.customer.delegate.CustomerListDelegate;
import helloworld.example.customer.list.CustomerSummaryObject;

/**
 *
 * @author TUYEN-DM
 * @version $Revision:   $ $Date:   $
 */
public class CustomerSearchAction extends Action{
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception{
		ActionForward forward = null;
		CustomerSearchForm searchform = (CustomerSearchForm)form;
		if((searchform.getSearchButton().isSelected()) || 
				("Search".equals(request.getParameter("action")))) {
			CustomerListDelegate delegate = new CustomerListDelegate();
			CustomerSummaryObject[] customers = delegate.findCustomers(searchform.getLastName());
			request.setAttribute("CUSTOMER_SUMMARY_OBJECTS", customers);
			forward = mapping.findForward("success");
		}
		return forward;		
	}

}
